﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

var handlerCool = {
    //同步提交处理程序地址
    url: '../Controllers/AsyHandler.ashx',
    type: "post",
    AjaxPost: function(data, callback) {
        $.ajax({
            url: this.url,
            data: data,
            //dataType: "json",
            type: this.type,
            async: false,
            success: function(result) {
                callback(result);
            },
            error: function(e) { }
        });
    }
}

var handler = {
    //异步提交处理程序地址
    url: '../Controllers/AsyHandler.ashx',
        type: "post",
    AjaxPost: function(data, callback) {
        $.ajax({
            url: this.url,
            data: data,
            //dataType: "json",
            type: this.type,
            async: true,
            success: function(result) {
                callback(result);
            },
            error: function(e) { }
        });
    }
}


var JsonhandlerCool = {
    //同步提交处理程序地址
    url: '../Controllers/AsyHandler.ashx',
    type: "post",
    cache: true,
    AjaxPost: function(data, callback) {
        $.ajax({
            url: this.url,
            data: data,
            dataType: "json",
            type: this.type,
            cache: this.cache,
            async: false,
            success: function(result) {
                callback(result);
            },
            error: function(e) { }
        });
    }
}

var Jsonhandler = {
    //异步提交处理程序地址
    url: '../Controllers/AsyHandler.ashx',
    type: "post",
    cache: true,
    AjaxPost: function(data, callback) {
        $.ajax({
            url: this.url,
            data: data,
            dataType: "json",
            type: this.type,
            cache: this.cache,
            async: true,
            success: function (result) {               
                callback(result);
            },
            error: function (e,c) {
                alert(c);
            }
        });
    }
}




//var data = MakeParameters('gg', 1);
//handler.AjaxPost(Call, data);
//      handler.data = {};
// handler.AjaxPost(Call);
//handler.data = {};
//handler.AjaxPost(Call);

function Extend(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
}

//构造传递的参数
function MakeParameters() {
    var data = { target: arguments[0], cmd: arguments[1] };
    var index = 0;
    for (var i = 2; i < arguments.length; i++) {

        var paramsName = 'params' + index;
        var arr = "{'" + paramsName + "':'" + arguments[i] + "'}";
        arr = eval('(' + arr + ')')
        jQuery.extend(data, arr);
        index++;
    }
    return data;
}

//异步提交表单  为Jquery框架扩展方法
(function($) {
    $.fn.ajaxForm = function(successCallback, validateCallback) {
        var form = $(this);

        form.submit(function() {
            if (validateCallback) {
                if (validateCallback()) {
                    $.ajax({
                        url: form.attr("action"),
                        type: form.attr("method"),
                        data: form.serialize(),
                        beforeSend: function(xhr) {
                        },
                        success: function(data) {
                            successCallback(data);
                        },
                        error: function() {

                            alert("请求出错，请重试");
                        },
                        complete: function() {
                        }
                    });
                }
                else {
                    return false;
                }
            }
            else {

                $.ajax({
                    url: form.attr("action"),
                    type: form.attr("method"),
                    data: form.serialize(),
                    beforeSend: function(xhr) {

                    },
                    success: function(data) {
                        successCallback(data);
                    },
                    error: function() {

                        alert("请求出错，请重试");
                    },
                    complete: function() {
                    }
                });
            }

            //            alert("3");
            return false;
        });
    };
    //    function showLoading() {
    //        $("#loading").css("display", "");
    //    };
    //    function hideLoading() {
    //        $("#loading").css("display", "none");
    //    };
})(jQuery); 